package cs2340.g21.wms;

import java.util.ArrayList;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.View;

public class HomeScreenActivity extends Activity {
    private Coordinator coordinator;
    
	protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        coordinator = new Coordinator();
        if(getIntent().getExtras() != null){
            coordinator = (Coordinator) getIntent().getExtras().getSerializable("cs2340.g21.wms.coordinator");
        }
		setContentView(R.layout.activity_mainscreen);
	}
	
	public void signOut(View view) {
		Intent intent = new Intent();
        coordinator.resetUser();
        intent.putExtra("cs2340.g21.wms.coordinator", coordinator);
        intent.setClass(HomeScreenActivity.this, LoginActivity.class);
        startActivity(intent);
        finish();
	}
	
    public void viewNotes(View view){
        Intent intent = new Intent();
        intent.putExtra("cs2340.g21.wms.coordinator", coordinator);
        intent.putExtra("notes", (ArrayList<Note>)coordinator.getUser().getNotes());
        intent.setClass(HomeScreenActivity.this, NoteListActivity.class);
        startActivity(intent);
        finish();
    }
	
	public void createItem(View view) {
		Intent intent = new Intent();
        intent.putExtra("cs2340.g21.wms.coordinator", coordinator);
        intent.setClass(HomeScreenActivity.this, CreateItemActivity.class);
        startActivity(intent);
        finish();
	}
	
	public void viewMyItems(View view) {
		Intent intent = new Intent();
        intent.putExtra("cs2340.g21.wms.coordinator", coordinator);
        intent.putExtra("items", (ArrayList<Item>)coordinator.getUser().getItems());
        intent.putExtra("original", (ArrayList<Item>)coordinator.getUser().getItems());
        intent.setClass(HomeScreenActivity.this, ItemListActivity.class);
        startActivity(intent);
        finish();
	}
	
	public void searchItem(View view) {
	    Intent intent = new Intent();
        intent.putExtra("cs2340.g21.wms.coordinator", coordinator);
        intent.setClass(HomeScreenActivity.this, SearchActivity.class);
        startActivity(intent);
        finish();
	}
	
    @Override
    public void onBackPressed() {
        Intent intent = new Intent();
        coordinator.resetUser();
        intent.putExtra("cs2340.g21.wms.coordinator", coordinator);
        intent.setClass(HomeScreenActivity.this, LoginActivity.class);
        startActivity(intent);
        finish();
    }
    
    public void viewMatches(View view){
        Intent intent = new Intent();
        ArrayList<Item> matches = (ArrayList<Item>)coordinator.getMatchList(coordinator.getUser());
        intent.putExtra("items", matches);
        intent.putExtra("original", matches);
        intent.putExtra("cs2340.g21.wms.coordinator", coordinator);
        intent.setClass(HomeScreenActivity.this, ItemListActivity.class);
        startActivity(intent);
        finish();
    }

}
